﻿#include "FITKJob.h"
#include "FITKAbaqusData.h"
#include "FITKDataCase.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaStepManager.h"

namespace AbaqusData
{
    //int FITKJob::MAXPROID = 0;
    FITKJob::FITKJob( /*bool bTemp*/ )
    {/*
        if ( !bTemp ) _proID = ++MAXPROID;*/
    }

    FITKJob::~FITKJob( )
    {
    }

    bool FITKJob::copy(FITKAbstractDataObject* obj)
    {
        FITKJob* oldObj = dynamic_cast<FITKJob*>(obj);
        if (oldObj == nullptr)return false;

        //任务参数数据拷贝
        setDataObjectName(oldObj->getDataObjectName());
        _description = oldObj->getDesctiption();
        _bMutiCPU = oldObj->isMutiCPU();
        _mutiCPUMode = oldObj->getMutiCPUMode();
        _nCPU = oldObj->getNCPU();
        _bGPU = oldObj->isGPU();
        _nGPU = oldObj->getNGPU();
        _nFields = oldObj->getNumberOfFields();
        _parallelMethod = oldObj->getParallelMethod();
        _runState = oldObj->getRunningState();
        _filePath = oldObj->getFilePath();
        _solveType = oldObj->getSolverType();
        return true;
    }

    const QString FITKJob::getDesctiption( ) const
    {
        return _description;
    }

    void FITKJob::setDesctiption( const QString str )
    {
        _description = str;
    }

    void FITKJob::setIsMutiCPU( bool b )
    {
        _bMutiCPU = b;
    }

    bool FITKJob::isMutiCPU( ) const
    {
        return _bMutiCPU;
    }

    void FITKJob::setMutiCPUMode( MutiCPUMode mode )
    {
        //设置CPU方法
        _mutiCPUMode = mode;
    }

    FITKJob::MutiCPUMode FITKJob::getMutiCPUMode( ) const
    {
        //获取CPU方法
        return _mutiCPUMode;
    }

    void FITKJob::setNCPU( int n )
    {
        //设置CPU数量
        _nCPU = n;
    }

    int FITKJob::getNCPU( ) const
    {
        //获取CPU数量
        return _nCPU;
    }

    void FITKJob::setIsGPU( bool b )
    {
        //设置是否使用GPU
        _bGPU = b;
    }

    bool FITKJob::isGPU( ) const
    {
        //获取GPU数量
        return _bGPU;
    }

    void FITKJob::setNGPU( int n )
    {
        //设置GPU的数量
        _nGPU = n;
    }

    int FITKJob::getNGPU( ) const
    {
        //获取GPU的数量
        return _nGPU;
    }

    void FITKJob::setNumberOfFields( int n )
    {
        //设置并行域个数
        _nFields = n;
    }

    int FITKJob::getNumberOfFields( ) const
    {
        //获取并行域个数
        return _nFields;
    }

    void FITKJob::setParallelMethod(FITKJob::ParallelMethod method )
    {
        //设置并行方法
        _parallelMethod = method;
    }

    FITKJob::ParallelMethod FITKJob::getParallelMethod( ) const
    {
        //获取并行方法
        return _parallelMethod;
    }

    void FITKJob::setRunningState( RunningState state )
    {
        //设置运行状态
        _runState = state;
    }

    FITKJob::RunningState FITKJob::getRunningState( ) const
    {
        //获取运行状态
        return _runState;
    }

    FITKJob::SolverType FITKJob::getSolverType( )
    {
        if (FITKAbaqusData::GetDataFromAppFrame()->getCurrentCaseID() == -1) //通过文件创建
        {
            return _solveType;
        }
        else  //通过model创建
        {
            auto currentCase = FITKAbaqusData::GetDataFromAppFrame()->getCurrentCase();
            if (currentCase == nullptr) return FITKJob::SolverType::STUnKonw;
            auto stepManager = currentCase->getStepManager();
            if (stepManager->getDataCount() != 2) return _solveType;
            Interface::FITKAbaAbstractStep::FITKAbaStepType tp = stepManager->getDataByIndex(1)->getStepType();
            if(tp == Interface::FITKAbaAbstractStep::DynamicExplicit)
             return FITKJob::SolverType::STExplicit;
            else return FITKJob::SolverType::STImplicit;
        
        }
        return FITKJob::SolverType::STImplicit;
    }

    void FITKJob::setFilePath( QString str )
    {
        //设置inp文件路径
        _filePath = str;
    }

    void FITKJob::setFilePathForInpJob( QString str )
    {
        _caseID   = -1;
        _filePath = str;
    }

    const QString& FITKJob::getFilePath( ) const
    {
        //获取文件路径
        return _filePath;
    }

    int FITKJob::getCaseID()
    {
        //获取算例id
        return _caseID;
    }

    void FITKJob::setCaseID(const int caseId)
    {
        //设置算例id
        _caseID = caseId;
    }

    bool FITKJob::isInpJob() const
    {
        //判断是否为inp文件任务
        return _caseID == -1;
    }

    void FITKJob::setSolveType( SolverType type )
    {
        //设置求解类型
        _solveType = type;
    }

}  // namespace Document
